package top.auntie.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.auntie.bean.OrgTypeReportQueryDto;
import top.auntie.bean.PageReq;
import top.auntie.dao.OrgTypeReportDao;
import top.auntie.dao.TypeDao;
import top.auntie.model.OrgTypeReport;
import top.auntie.service.OrgTypeReportService;
import top.auntie.util.DateTimeUtils;

@Slf4j
@Service
public class OrgTypeReportServiceImpl implements OrgTypeReportService {

    @Autowired
    private OrgTypeReportDao orgTypeReportDao;

    @Autowired
    private TypeDao typeDao;


    @Override
    public PageInfo<?> queryOrgTypeReport(PageReq pageReq) {
        PageHelper.startPage(pageReq.getPage(), pageReq.getLimit(), true);
        return new PageInfo<>(orgTypeReportDao.queryReport());
    }

    @Override
    public void saveOrgTypeReport(OrgTypeReport orgTypeReport) {
        if (orgTypeReport.getId()!=null) {
            orgTypeReport.setUpdatedAt(DateTimeUtils.getNowDateTimeStr());
            orgTypeReportDao.updateByPrimaryKeySelective(orgTypeReport);
        } else {
            orgTypeReport.setCreatedAt(DateTimeUtils.getNowDateTimeStr());
            orgTypeReportDao.insertSelective(orgTypeReport);
        }
    }

    @Override
    public PageInfo<?> queryReportByDateAndOrgId(String date, String orgId) {
        return null;
    }

    @Override
    public PageInfo<?> queryReportByDate(OrgTypeReportQueryDto dto) {
//        PageHelper.startPage(dto.getPage(), dto.getLimit(), true);
        return new PageInfo<>(orgTypeReportDao.queryReportByDate(dto.getDate()));
    }

    @Override
    public PageInfo<?> queryOrgTypeReportByOrg(OrgTypeReportQueryDto dto) {
        return null;
    }


}
